﻿using System;
using System.Collections.Generic;
using UnityEngine;

namespace Battle.View
{
    public class CGuideSkillCallback : IBattleSkillCallback
    {
        CGuideBattleViewCtrl viewCtrl;
        public CGuideSkillCallback(CGuideBattleViewCtrl viewCtrl)
        {
            this.viewCtrl = viewCtrl;
        }

        public void OnSkillBegin(BattleSkill skill)
        {

        }

        public void OnSkillEnd(BattleSkill skill)
        {
            if (viewCtrl.curGuideStep == CGuideBattleViewCtrl.GuideStep.Kirito_FirstSkill_Casting_Pre &&
                skill.heroId == CGuideBattleViewCtrl.kiritoHeroId &&
                skill.skillType == SkillType.Skill1)
            {
                Debug.LogError("[CGuideSkillCallback] OnSkillEnd, GuideStep Error. curstep:" + viewCtrl.curGuideStep.ToString());
                viewCtrl.curGuideStep = CGuideBattleViewCtrl.GuideStep.None;
            }
            else if (viewCtrl.curGuideStep == CGuideBattleViewCtrl.GuideStep.Kirito_SecondSkill_Casting_Pre &&
                skill.heroId == CGuideBattleViewCtrl.kiritoHeroId &&
                skill.skillType == SkillType.Skill2)
            {
                Debug.LogError("[CGuideSkillCallback] OnSkillEnd, GuideStep Error. curstep:" + viewCtrl.curGuideStep.ToString());
                viewCtrl.curGuideStep = CGuideBattleViewCtrl.GuideStep.None;
            }
            else if (viewCtrl.curGuideStep == CGuideBattleViewCtrl.GuideStep.First_Combo_Casting_Pre &&
                (skill.GetOwnBC().heroClass == (int)HeroClass.Main_Actor_Man || skill.GetOwnBC().heroClass == (int)HeroClass.Main_Actor_Woman) &&
                skill.skillType == SkillType.Skill1)
            {
                Debug.LogError("[CGuideSkillCallback] OnSkillEnd, GuideStep Error. curstep:" + viewCtrl.curGuideStep.ToString());
                viewCtrl.curGuideStep = CGuideBattleViewCtrl.GuideStep.None;
            }
            else if (viewCtrl.curGuideStep == CGuideBattleViewCtrl.GuideStep.Second_Combo_Casting_Pre &&
                skill.heroId == CGuideBattleViewCtrl.asunaHeroId &&
                skill.skillType == SkillType.Skill2)
            {
                Debug.LogError("[CGuideSkillCallback] OnSkillEnd, GuideStep Error. curstep:" + viewCtrl.curGuideStep.ToString());
                viewCtrl.curGuideStep = CGuideBattleViewCtrl.GuideStep.None;
            }
        }

        public void OnSkillEnqueue(BattleSkill skill)
        {
            if (viewCtrl.curGuideStep == CGuideBattleViewCtrl.GuideStep.Kirito_FirstSkill_Cast &&
                skill.GetOwnBC().heroId == CGuideBattleViewCtrl.kiritoHeroId &&
                skill.skillType == SkillType.Skill1)
            {
                viewCtrl.curGuideStep = CGuideBattleViewCtrl.GuideStep.Kirito_FirstSkill_Casting_Pre;
                BattleManager.Instance.battlePanel.guidePanel.Show(null, false, CGuideBattleViewCtrl.GuideStep.Kirito_FirstSkill_Casting_Pre);
            }
            else if (viewCtrl.curGuideStep == CGuideBattleViewCtrl.GuideStep.MainHero_Combo_FirstSkill_Cast &&
                (skill.GetOwnBC().heroClass == (int)HeroClass.Main_Actor_Man || skill.GetOwnBC().heroClass == (int)HeroClass.Main_Actor_Woman) &&
                skill.skillType == SkillType.Skill1)
            {
                Time.timeScale = 1f;
                viewCtrl.curGuideStep = CGuideBattleViewCtrl.GuideStep.First_Combo_Casting_Pre;
                BattleManager.Instance.battlePanel.guidePanel.Show(null, false, CGuideBattleViewCtrl.GuideStep.First_Combo_Casting_Pre);
            }
            else if (viewCtrl.curGuideStep == CGuideBattleViewCtrl.GuideStep.Kirito_SecondSkill_Cast &&
                skill.GetOwnBC().heroId == CGuideBattleViewCtrl.kiritoHeroId &&
                skill.skillType == SkillType.Skill2)
            {
                viewCtrl.curGuideStep = CGuideBattleViewCtrl.GuideStep.Kirito_SecondSkill_Casting_Pre;
                BattleManager.Instance.battlePanel.guidePanel.Show(null, false, CGuideBattleViewCtrl.GuideStep.Kirito_SecondSkill_Casting_Pre);
            }
            else if (viewCtrl.curGuideStep == CGuideBattleViewCtrl.GuideStep.Asuna_Combo_SecondSkill_Cast &&
                skill.GetOwnBC().heroId == CGuideBattleViewCtrl.asunaHeroId &&
                skill.skillType == SkillType.Skill1)
            {
                Time.timeScale = 1f;
                viewCtrl.curGuideStep = CGuideBattleViewCtrl.GuideStep.Second_Combo_Casting_Pre;
                BattleManager.Instance.battlePanel.guidePanel.Show(null, false, CGuideBattleViewCtrl.GuideStep.Second_Combo_Casting_Pre);
            }
        }

        public void OnSkillRelease(BattleSkillRelease release, BattleCharacter target)
        {
            if (viewCtrl.curGuideStep == CGuideBattleViewCtrl.GuideStep.Kirito_FirstSkill_Casting_Pre &&
                release.ownBC.heroId == CGuideBattleViewCtrl.kiritoHeroId &&
                release.SkillType == SkillType.Skill1 &&
                release.HSRId == BattleSkillRelease.GetComboGuideFloatReleaseId())
            {
                Time.timeScale = 0f;
                viewCtrl.curGuideStep = CGuideBattleViewCtrl.GuideStep.Kirito_FirstSkill_Casting_Pause;
                BattleManager.Instance.battlePanel.guidePanel.Show(null, false, CGuideBattleViewCtrl.GuideStep.Kirito_FirstSkill_Casting_Pause);
            }
            else if (viewCtrl.curGuideStep == CGuideBattleViewCtrl.GuideStep.Kirito_SecondSkill_Casting_Pre &&
                release.ownBC.heroId == CGuideBattleViewCtrl.kiritoHeroId &&
                release.SkillType == SkillType.Skill2 &&
                release.HSRId == BattleSkillRelease.GetComboGuideFallReleaseId())
            {
                Time.timeScale = 0f;
                viewCtrl.curGuideStep = CGuideBattleViewCtrl.GuideStep.Kirito_SecondSkill_Casting_Pause;
                BattleManager.Instance.battlePanel.guidePanel.Show(null, false, CGuideBattleViewCtrl.GuideStep.Kirito_SecondSkill_Casting_Pause);
            }
            else if (viewCtrl.curGuideStep == CGuideBattleViewCtrl.GuideStep.First_Combo_Casting_Pre &&
                (release.ownBC.heroClass == (int)HeroClass.Main_Actor_Man || release.ownBC.heroClass == (int)HeroClass.Main_Actor_Woman) &&
                release.SkillType == SkillType.Skill1 &&
                !viewCtrl.isAngerBallDropped && 
                target != null)
            {
                //viewCtrl.AddDropWaterBall(target, new Vector3(0,0,-1f));
                viewCtrl.isAngerBallDropped = true;
                viewCtrl.AddDropWaterBall(target, release.ownBC, 1f, new Vector3(0, 0, -1), new Vector3(0, 3, -1));
            }
            else if (viewCtrl.curGuideStep == CGuideBattleViewCtrl.GuideStep.Second_Combo_Casting_Pre &&
                release.ownBC.heroId == CGuideBattleViewCtrl.asunaHeroId &&
                release.SkillType == SkillType.Skill1 &&
                !viewCtrl.isFireBallDropped &&
                target != null)
            {
                //viewCtrl.AddDropFireBall(release.ownBC, target, new Vector3(0,0,-1));
                viewCtrl.isFireBallDropped = true;
                viewCtrl.AddDropFireBall(target, release.ownBC, 1f, new Vector3(0, 0, -1), new Vector3(0, 3, -1));
            }
        }

    }
}
